Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2c fixes #204

Merged
merged 5 commits into from
Jan 15, 2024
Merged

I2c fixes #204

merged 5 commits into from
Jan 15, 2024

Conversation

jlaitine
Copy link

Summary

This fixes some issues with initializing, re-initializing and resetting mpfs i2c + adds some debug capabilities for the future use if ever needed

Impact

Fixes the issue where a failing magnetometer (wire getting loose) knocks out cold the whole bus, including voltage measurements, lidar lite and barometers.

Testing

On-desk tested with saluki-v2 with core-i2c

@jlaitine jlaitine requested review from eenurkka and pussuw January 11, 2024 11:00
Copy link

@eenurkka eenurkka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right!

@jlaitine jlaitine force-pushed the i2c_fixes branch 2 times, most recently from 4896164 to 7ef842c Compare January 11, 2024 13:04
…g/deinitializing bus

Ensure that there are no pending state or interrupts in the i2c controller. This removes
errors caused by deinitialize/initialize sequences in error cases.

Signed-off-by: Jukka Laitinen <[email protected]>
Add more error status codes to help debugging in the future.

Signed-off-by: Jukka Laitinen <[email protected]>
- Use mpfs_i2c_deinit+mpfs_i2c_init sequence to re-initialize i2c block
- Use the i2c mutex to protect the reset; in case there are several devices
  on the same bus, and one of them resets the bus, reset must not occur in
  the middle of another device's transfer.
- Move irq attach to the i2c_init as the irq detach is in i2c_deinit

Signed-off-by: Jukka Laitinen <[email protected]>
Add sanity checks for debugging possible errors in the driver.

Signed-off-by: Jukka Laitinen <[email protected]>
@jlaitine
Copy link
Author

I added one more commit to this PR, to recover better from warm reboot

@jlaitine
Copy link
Author

There is still problems reported by testing. Not merging this PR yet, but will continue with measuring the buses after warm reset

@eenurkka
Copy link

eenurkka commented Jan 15, 2024

Just a desperate idea, try setting SMBus_Reset to 1? (I wonder if disabling the module will stop the clk though)

"The I2C protocol specification does not require a specific bus time-out period and typically, the slave device can hold (clock-stretch) the clock line low indefinitely. The SMBus protocol requires a bus time-out of 35 ms, and the PMBus™ protocol requires a bus time-out period of 25 to 35 ms. The purpose of implementing a bus time-out is to prevent stalled devices from indefinitely holding the bus during communication. Although not required by the normal I2C specification, a defined bus time-out may be advantageous as a fail-safe, in events where a stall in communication occurs."

CoreI2C:

SMBus_Reset W Writing a one to this bit will force the clock line low until 35 ms has 
been exceeded, thus resetting the entire bus as per the SMBus  Specification Version 2.0. 
Usage: When the channel is used as a host controller (master), the 
user can decide to reset the bus by holding the clock line low 
35ms. Slaves must react to this event and reset themselves.

@jlaitine
Copy link
Author

Verified with oscilloscope that there is no issue with some slave holding the bus.

The following is observed: If the device is reset in the middle of read sequence, before the interrupt is cleared, after the warm boot it is not possbile to get any more interrupts from that i2c block. It is possible to poll the irq status and write to the bus properly, but there are just no irqs -> hence the bus gets stuck at every "start" condition...

I'd say that these fixes are good to go, and more investigation is needed for the remaining issue.

@jlaitine
Copy link
Author

Merging this->

@jlaitine jlaitine merged commit 15391f4 into master Jan 15, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants